package com.eas.biz.service.user.impl;

import java.util.List;

import javax.annotation.Resource;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.eas.biz.dao.user.dataobject.StudentDO;
import com.eas.biz.dao.user.interfaces.StudentDao;
import com.eas.biz.framework.BaseQuery;
import com.eas.biz.service.user.domain.ClassInfo;
import com.eas.biz.service.user.domain.SchoolInfo;
import com.eas.biz.service.user.interfaces.ClassService;
import com.eas.biz.service.user.interfaces.SchoolService;
import com.eas.biz.service.user.interfaces.StudentService;

@Service("studentService")
public class StudentServiceImpl implements StudentService {

    @Autowired
    private StudentDao studentDao;

    @Resource(name = "classCacheService")
    private ClassService classService;

    @Resource(name = "schoolCacheService")
    private SchoolService schoolService;

    public StudentDO selectById(long id) {
        return studentDao.selectById(id);
    }

    public long insert(StudentDO student) {
        return studentDao.insert(student);
    }

    public int deleteById(long id) {
        return studentDao.deleteById(id);
    }

    public int update(StudentDO student) {
        return studentDao.update(student);
    }

    public List<StudentDO> selectByQuery(BaseQuery query) {
        return studentDao.selectByQuery(query);
    }

    public int countByQuery(BaseQuery query) {
        return studentDao.countByQuery(query);
    }

    public String getSchoolName(long id) {
        StudentDO student = studentDao.selectById(id);
        if (student != null) {
            SchoolInfo school = schoolService.getSchoolInfo(student.getSchoolId());
            return school != null ? school.getName() : "";
        } else {
            return null;
        }

    }

    public String getClassFullName(long id) {
        StudentDO student = studentDao.selectById(id);
        if (student != null) {
            ClassInfo classInfo = classService.getClassInfo(student.getClassId());
            return classInfo.getClassFullName();
        } else {
            return null;
        }

    }
}
